package CoreThreadFactory;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class UserThreadPool {
    public static void main(String[] args) {
        BlockingQueue queue = new LinkedBlockingQueue(2);
        UserThreadFactory f1 = new UserThreadFactory("第一机房");
        UserThreadFactory f2 = new UserThreadFactory("第二机房");
        UserRejectHandler handler = new UserRejectHandler();
        ThreadPoolExecutor threadPoolExecutor1 =
                new ThreadPoolExecutor(1, 2, 60, TimeUnit.SECONDS, queue, f1, handler);
        ThreadPoolExecutor threadPoolExecutor2 =
                new ThreadPoolExecutor(1, 2, 60, TimeUnit.SECONDS, queue, f2, handler);
        Runnable task = new Task();
        for (int i = 0; i < 20; i++) {
//            threadPoolExecutor1.execute(task);
            threadPoolExecutor2.execute(task);
        }
    }
}
